home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 4: GNU Archives / Linux Cubed Series 4 - GNU Archives.iso / gnu / fontutil.6 / fontutil / fontutils-0.6 / lib / fix-num.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-03-27  |  1.1 KB  |  44 lines

  1. /* fix-num.c: conversions on ``fixnums'', which are a 32-bit
  2.    word with 20 bits of fraction.
  3.  
  4. Copyright (C) 1992 Free Software Foundation, Inc.
  5.  
  6. This program is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 2, or (at your option)
  9. any later version.
  10.  
  11. This program is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with this program; if not, write to the Free Software
  18. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  19.  
  20. #include "config.h"
  21.  
  22. #include "fix-num.h"
  23.  
  24.  
  25. #define FIX_UNITY (1 << 20)
  26.  
  27.  
  28. const real
  29. fix_to_real (fix_word f)
  30. {
  31.   real r = f / FIX_UNITY + ((real) (f % FIX_UNITY) / (real) FIX_UNITY);
  32.  
  33.   return r;
  34. }
  35.  
  36.  
  37. const fix_word
  38. real_to_fix (real r)
  39. {
  40.   fix_word f = floor (r) * FIX_UNITY + (r - floor (r)) * FIX_UNITY;
  41.  
  42.   return f;
  43. }
  44.